using NodeCanvas.Framework;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.AI.Node
{
    public class AIConditionBaseNode : ConditionTask
    {
        protected AIEntity _entity;
        
        protected Transform _transform;
        protected Animator _animator;

        protected int _aiUniqueID;
        
        protected bool _isPlayer;

        protected override string OnInit()
        {
            _entity = ownerSystemBlackboard.GetVariable<AIEntity>("AIEntity").value;
            if (_entity && _entity.viewer!=null)
            {
                _transform = _entity.viewer.transform;
                _animator = _entity.viewer.animator;
            }
      
            _aiUniqueID = ownerSystemBlackboard.GetVariable<int>("UniqueID").value;
            _isPlayer = LibertyAIUtils.PLAYER_AI_ID == _aiUniqueID;
            return null;
        }

        protected override void OnPreCheck()
        {
            if (_entity == null)
            {
                _entity = ownerSystemBlackboard.GetVariable<AIEntity>("AIEntity").value;
                if (_entity && _entity.viewer != null)
                {
                    _transform = _entity.viewer.transform;
                    _animator = _entity.viewer.animator;
                }
    
                _aiUniqueID = ownerSystemBlackboard.GetVariable<int>("UniqueID").value;
                _isPlayer = LibertyAIUtils.PLAYER_AI_ID == _aiUniqueID;
            }
        }
    }
}